/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package formularios;

import java.sql.ResultSet;
import java.util.Date;
import javax.swing.JOptionPane;

/**
 *
 * @author Jrg
 */
public class ingresoCuotas extends javax.swing.JDialog {
    
    inscripciones _inscripcion;
    Date _del, _al;
    int _idAlumno;
    
    /**
     * Creates new form ingresoCuotas
     */
    public ingresoCuotas(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        this.setLocationRelativeTo(null);
    }
    
    public ingresoCuotas(java.awt.Frame parent, boolean modal, inscripciones inscripcion, Date del, Date al,int idalumno) 
    {
        super(parent, modal);
        initComponents();
        this.setLocationRelativeTo(null);
        _inscripcion = inscripcion;
        _del=del;
        _al=al;
        _idAlumno=idalumno;
        ObtenerCuotasAlumno();
    }
    
    private void ObtenerCuotasAlumno()
    {
        try
        {
            ResultSet rs=null;
            rs=MainMenu.conexion.EjecutarConsulta("select colegiatura, ingles, intecap from alumnos where idalumno="+_idAlumno);
            if (rs.next())
            {
                tfColegiatura.setText(rs.getString("colegiatura"));
                tfIngles.setText(rs.getString("ingles"));
                tfIntecap.setText(rs.getString("intecap"));
            }
        }
        catch(Exception ex)
        {
            
        }
    }
    
    private void AgregarCuotas()
    {
        double colegiatura=0;
        double ingles =0;
        double intecap=0;
        try 
        {
            colegiatura= (double)Math.round(Double.valueOf(tfColegiatura.getText())*100)/100;
            ingles= (double)Math.round(Double.valueOf(tfIngles.getText())*100)/100;
            intecap= (double)Math.round(Double.valueOf(tfIntecap.getText())*100)/100;
        }
        catch(Exception ex){}
       
        if (_del.compareTo(_al)<0) //del es menor a al
        {
            int delMes= _del.getMonth();
            int alMes =_al.getMonth();
            for (int i = delMes; i <= alMes; i++) 
            {
                Date vencimiento = new Date();
                vencimiento.setYear(_del.getYear());
                vencimiento.setMonth(i+1);
                vencimiento.setDate(5);
                if(colegiatura>0)
                {
                    _inscripcion.Add(2, "Colegiatura", colegiatura,vencimiento);
                }
                if(ingles>0)
                {
                    _inscripcion.Add(3, "Ingles", ingles,vencimiento);
                }
                if(intecap>0)
                {
                    _inscripcion.Add(4, "Intecap", intecap,vencimiento);
                }
                
            }
            this.setVisible(false);
        }
        else
             JOptionPane.showMessageDialog(this, "El rango de fechas es incorrecto","Error",JOptionPane.ERROR_MESSAGE);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        tfColegiatura = new javax.swing.JTextField();
        btnAgregar = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        tfIngles = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        tfIntecap = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        tfColegiatura.setHorizontalAlignment(javax.swing.JTextField.RIGHT);

        btnAgregar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/accept24.png"))); // NOI18N
        btnAgregar.setText("Agregar");
        btnAgregar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAgregarActionPerformed(evt);
            }
        });

        jLabel1.setText("Colegiatura");

        jLabel2.setText("Ingles");

        tfIngles.setHorizontalAlignment(javax.swing.JTextField.RIGHT);

        jLabel3.setText("Intecap");

        tfIntecap.setHorizontalAlignment(javax.swing.JTextField.RIGHT);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3))
                .addGap(0, 0, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addGap(93, 93, 93)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(tfIntecap, javax.swing.GroupLayout.DEFAULT_SIZE, 103, Short.MAX_VALUE)
                    .addComponent(tfIngles)
                    .addComponent(tfColegiatura)
                    .addComponent(btnAgregar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(72, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(tfColegiatura, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(tfIngles, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addComponent(tfIntecap, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(btnAgregar)
                .addContainerGap(16, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnAgregarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAgregarActionPerformed
        AgregarCuotas();
    }//GEN-LAST:event_btnAgregarActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ingresoCuotas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ingresoCuotas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ingresoCuotas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ingresoCuotas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                ingresoCuotas dialog = new ingresoCuotas(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAgregar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JTextField tfColegiatura;
    private javax.swing.JTextField tfIngles;
    private javax.swing.JTextField tfIntecap;
    // End of variables declaration//GEN-END:variables
}
